package com.ipartek.pruebas.bbddaccessP1;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

import com.ipartek.pruebas.bean.*;
import com.ipartek.pruebas.excepciones.AlumnoException;

public class AlumnoMYSQLDAOP1 implements AlumnoDAOP1{
	
	Connection con;
	PreparedStatement ptmt = null;
	ResultSet result = null;
	
	public List<Alumno> getAlumnos(){
		List<Alumno> list = new ArrayList<Alumno>();
		
		try{
			String sql = "SELECT * FROM Alumnos;";
			con = MYSQLDAOFactoryP1.getConnection();
			ptmt = con.prepareStatement(sql);
			result = ptmt.executeQuery();
			while(result.next()){
				
			}
			
		}catch(SQLException e){
			e.printStackTrace();
		}
		
		return list;
		
	}

	@Override
	public boolean udapteAlumno(Alumno alu) throws AlumnoException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public Alumno getAlumnoByDni(String dni) throws AlumnoException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean deleteAlumno(String dni) throws AlumnoException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean insertAlumno(Alumno alu) throws AlumnoException {
		int i = 0;
		boolean resultado = false;
		String sql = "INSERT INTO alumno VALUES ('"+alu.getNombre()+"','"+alu.getApellido1()+"','"+alu.getApellido2()+"','"+alu.getDni()+"');";
		try{
		con = MYSQLDAOFactoryP1.getConnection();
		ptmt = con.prepareStatement(sql);
		i = ptmt.executeUpdate();
		}catch(SQLException e){
			e.printStackTrace();
		}
		if(i == 1){
			resultado = true;
		}
		
		return resultado;
	}
}
